package com.stx.servlet.car;

import com.stx.bean.Car;
import com.stx.mapper.CarMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
/*车辆详情页面跳转*/
@WebServlet(urlPatterns = {"/carDetailPage"})
public class CarDetailPageIServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        try {
            Car car = CarMapper.findCarById(id);
            HttpSession session = req.getSession();
            session.setAttribute("carDetail", car);
            req.getRequestDispatcher("/carDetail.jsp").forward(req,resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
